package com.code.day05;

public class Day05ComplexArray {
    public static void main(String[] args) {
        /**
         * 数组扩容
         *
         * 数组扩容需要创建新数组,然后吧老数组的元素复制到新数组中,然后将新数组的地址值赋值给老数组
         */
        int[] arr1 = {1,2,3};
        //创建新数组
        int[] arr2 = new int[6];
        //将arr1中的元素放到arr2数组中
        for (int i = 0; i< arr1.length; i++) {

            arr2[i] = arr1[i];
        }
        //将arr2的地址值赋值给arr1
         arr1 = arr2;       //扩容成为6个元素的数组

        for (int i = 0; i < arr1.length; i++) {
            System.out.println(arr1[i]);
        }
        /**
         * 数组合并
         */
        int[] arr3 = {1,2,3};
        int[] arr4 = {4,5,6};
        int[] arr5 = new int[arr3.length + arr4.length];

        for (int i = 0; i < arr3.length; i++){
            arr5[i] = arr3[i];
        }
        for(int j =0 ;j< arr4.length; j++){
            arr5[arr3.length + j] = arr4[j];
        }

        for (int f=0 ; f< arr5.length; f++){
            System.out.println(arr5[f]);
        }
    }
}
